#ifndef FND_GAME_2D_DRAWER_HPP
#define FND_GAME_2D_DRAWER_HPP
#include "thinker.hpp"
#include <sfml/graphics.hpp>
#include <boost/bind.hpp>
namespace FndGame2D {
  typedef boost::function<void (sf::RenderTarget&)> drawer_render_type ; 
  class drawer : public thinker {
  public:
    explicit drawer(const std::string& name = std::string(), int draw_l = 0) : thinker(name),
									       m_draw_level(draw_l) {
      add_property(can_render, true) ;
      add_property(is_show, true) ;
      renderer = boost::bind(&drawer::dummy_renderer, this, _1) ;
    }
  public:
    void render(sf::RenderTarget& target) { renderer(target) ;}
    int draw_level() const {return m_draw_level ;}
  private:
    int m_draw_level  ;
  public:
    drawer_render_type renderer ;
  protected:
    void dummy_renderer(sf::RenderTarget&) {}
  public:
    static const std::string can_render ;
    static const std::string is_show ;
  } ;
  class drawer_level_find : public std::unary_function<drawer*, bool> {
  public:
    bool operator()( const drawer* d2) const {
      return (m_d->draw_level() == d2->draw_level() && m_d->name() == d2->name()) ;
    }
    drawer_level_find(const drawer* d1) : m_d(d1) {}
    const drawer* m_d ;

  } ;

  class drawer_level_compare : public std::binary_function<drawer*, drawer*, bool> {
  public:
    bool operator()(const drawer* d1, const drawer* d2) const {
      if(d1->draw_level() == d2->draw_level()) return d1->name() < d2->name() ;
      return d1->draw_level() < d2->draw_level() ;
    }
  } ;
}
#endif
